package br.com.atid.view.util
{
    import com.esri.ags.Map;
    import com.esri.ags.geometry.Geometry;
    import com.esri.ags.geometry.MapPoint;
    import com.esri.ags.geometry.Polyline;
    import com.esri.ags.symbol.Symbol;
    
    import flash.display.Sprite;

    public class SolidLineSymbol extends Symbol
    {
        public var alpha : Number = 1.0;
        public var width : Number = 1.0;
        public var color : Number = 0x000000;
        
        public function SolidLineSymbol()
        {
            super();
        }
        
        override public function clear(sprite:Sprite):void
        {
            sprite.graphics.clear();
        }
        
        private var m_func : Function;
        
        override public function draw(sprite:Sprite, geometry:Geometry, attributes:Object, map:Map):void
        {
            sprite.x = sprite.y = 0;
            if( geometry is Polyline )
            {
                sprite.graphics.lineStyle( width, color, alpha);
                const polyline : Polyline = Polyline(geometry);
                for each ( var path : Array in polyline.paths)
                {
                    m_func = moveTo;
                    for each ( var mapPoint : MapPoint in path)
                    {
                        m_func( sprite, mapPoint, map );
                    }                                                                 
                }
            }
        }
        
        private function moveTo( sprite : Sprite, mapPoint : MapPoint, map : Map ) : void
        {
            sprite.graphics.moveTo( toScreenX(map, mapPoint.x), toScreenY(map,mapPoint.y));
            m_func = lineTo;
        } 
        
        private function lineTo( sprite : Sprite, mapPoint : MapPoint, map : Map ) : void
        {
            sprite.graphics.lineTo( toScreenX(map, mapPoint.x), toScreenY(map,mapPoint.y));
        } 
        
    }
}